package com.pro.addresslist.tools;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.util.Log;


/**
 * Created by leekh on 2016/11/10.
 */
public class NetUtil {

    public enum  NetType {
        WIFI, GPRS, NET,
    }

    /**
     * 检测网络是否可用
     * @return
     */

	public static boolean isNetworkAvailable(Context context)
    {
        boolean isNetworkOK = false;
		try 
		{
	        ConnectivityManager conn = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
	        if (null == conn || null == conn.getActiveNetworkInfo()) 
	        {
	            isNetworkOK = false;
	            //Log.i(TAG, "No Active Network");
	        }
	        else 
	        {
	            isNetworkOK = true;
	            String netType = conn.getActiveNetworkInfo().getTypeName();
	            if ("WIFI".equalsIgnoreCase(netType)) 
	            {
	            	//Log.i(TAG, "Active Network is WIFI");
	            } 
	            else 
	            {
	            	//Log.i(TAG, "Active Network is mobile");
	            }
	        }
		} 
		catch (Exception e) 
		{
			e.printStackTrace();
		}
        return isNetworkOK;
    }
    /**
     * 获取当前网络类型
     * @return
     */
    public NetType getNetType() {
        return NetType.WIFI;
    }
}
